package com.ljy.my_study.java.thread.threadlocal;

/**
 * @author lijunying
 * @date 2021/6/17 9:56
 */
public class InheritableThreadLocalTestTask implements Runnable{

    private ThreadLocal<String> threadLocal;
    private InheritableThreadLocal<String> inheritableThreadLocal;

    public InheritableThreadLocalTestTask(ThreadLocal<String> threadLocal, InheritableThreadLocal<String> inheritableThreadLocal) {
        this.threadLocal = threadLocal;
        this.inheritableThreadLocal = inheritableThreadLocal;
    }

    public void setName(String name){
        this.threadLocal.set(name);
    }

    @Override
    public void run() {
        System.out.println("threadName："+Thread.currentThread().getName()+"，threadLocal name:"+this.threadLocal.get());
        System.out.println("threadName："+Thread.currentThread().getName()+"，inheritableThreadLocal name:"+this.inheritableThreadLocal.get());
    }
}
